package assets.loading;

import java.util.HashMap;
import java.util.Map;

import assets.Asset;

/** Handles sequential, blocking load operations for known asset types.
 * 
 * @author Joel Rausch
 */
public class AssetLoader {

	/** Enumeration of asset types. */
	public enum AssetType {
		UnknownType
	}
	
	/** Associates loaders with the types they can load. */
	private final Map<AssetType, ILoader> loaderMap;
	
	/** Default constructor. */
	public AssetLoader() {
		loaderMap = new HashMap<AssetType, ILoader>();
	}
	
	/**
	 * Synchronously load a named asset. Failure causes a null
	 * value to be returned.
	 * @param name
	 * @return
	 * @throws LoadException 
	 */
	public Asset loadAsset(String name) throws LoadException {
		// Resolve which loader to use
		AssetType type = resolveName(name);
		ILoader loader = loaderMap.get(type);
		if(loader != null) {
			return loader.load(name);
		} else {
			return null;
		}
	}
	
	/**
	 * Resolves the name to an asset type based on the file
	 * extension. An unknown extension will cause UnknownType to
	 * be returned.
	 * @param name
	 * @return
	 */
	public static AssetType resolveName(String name) {
		return AssetType.UnknownType;
	}
}
